package site.jlopen.secret;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import jakarta.annotation.Resource;
import site.jlopen.secret.config.SecretClientProperties;
import site.jlopen.secret.service.impl.SecretDataImpl;
import site.jlopen.secret.service.impl.SecretDatasourceImpl;
import site.jlopen.secret.service.impl.SecretGrapImpl;
import site.jlopen.secret.service.impl.SecretJobImpl;
import site.jlopen.secret.service.impl.SecretNodeImpl;
import site.jlopen.secret.service.impl.SecretProjectImpl;
import site.jlopen.secret.service.impl.SecretResultImpl;
import site.jlopen.secret.service.impl.SecretRouteImpl;
import site.jlopen.secret.service.impl.SecretServingImpl;
import site.jlopen.secret.service.intf.SecretAuthService;
import site.jlopen.secret.service.intf.SecretDataManage;
import site.jlopen.secret.service.intf.SecretDatasourceManage;
import site.jlopen.secret.service.intf.SecretGrapManage;
import site.jlopen.secret.service.intf.SecretJobManage;
import site.jlopen.secret.service.intf.SecretNodeManage;
import site.jlopen.secret.service.intf.SecretProjectManage;
import site.jlopen.secret.service.intf.SecretResultManage;
import site.jlopen.secret.service.intf.SecretRouteManage;
import site.jlopen.secret.service.intf.SecretServingManage;

/**
* @ClassName: KusciaClientConfig
* @Description: 客户端配置启动
* @author ChenJiaLu
* @date 2024年9月26日 下午5:58:53
*
 */
@AutoConfiguration
@EnableConfigurationProperties({SecretClientProperties.class})
public class SecretClientConfig {

	@Resource
	private SecretClientProperties clientProperties;
	
	@Bean
	public SecretAuthService authService() {
    	return new SecretAuthService(clientProperties);
    }
	
	@Bean
	public SecretDataManage dataManage() {
	    return new SecretDataImpl(clientProperties);
	}
	
	@Bean
	public SecretDatasourceManage datasourceManage() {
	    return new SecretDatasourceImpl(clientProperties);
	}
	
	@Bean
	public SecretRouteManage routeManage() {
	    return new SecretRouteImpl(clientProperties);
	}
	
	@Bean
	public SecretJobManage jobManage() {
	    return new SecretJobImpl(clientProperties);
	}
	
	@Bean
	public SecretNodeManage nodeManage() {
	    return new SecretNodeImpl(clientProperties);
	}
	
	@Bean
	public SecretResultManage resultManage() {
	    return new SecretResultImpl(clientProperties);
	}
	
	@Bean
	public SecretServingManage servingManage() {
	    return new SecretServingImpl(clientProperties);
	}
	
	@Bean
	public SecretGrapManage secretGrapManage() {
	    return new SecretGrapImpl(clientProperties);
	}
	
	@Bean
	public SecretProjectManage secretProjectManage() {
	    return new SecretProjectImpl(clientProperties);
	}
	
	@Bean
	public SecretResultManage secretResultManage() {
	    return new SecretResultImpl(clientProperties);
	}


	/**@PostConstruct**/
	/*public void init() {
		if(clientProperties.isEnable()) {
			SecretClientHttp<String> clientRequest = new SecretClientHttp<String>(clientProperties);
			Map<String, Object> form = new SecretReqBaseForm<Object>()
					.appId(clientProperties.getAppId())
					.add("username", clientProperties.getAppId())
					.add("password", clientProperties.getAppSecret());
			SecretClientResponse<String>  res = clientRequest.execute(SecretReqUrl.AUTH_URL, form);
			if(res.getStatus() == SecretClientHttpErrorCode.SUCCESS) {
				System.err.println("secret sdk 登录成功");
				clientProperties.setToken(res.getData());
			}
		}
	}*/
}
